<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateNewsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('news', function (Blueprint $table) {
            $table->increments('id')->unsigned()->comment('资讯表');
            $table->integer('object_id')->comment('发布对象id user_id/admin_user_id');
            $table->string('object_type')->comment('对象类型');
            $table->string('title')->comment('标题');
            $table->string('subtitle')->nullable()->comment('副标题');
            $table->string('front_cover')->nullable()->comment('封面');
            $table->text('content')->nullable()->comment('内容');
            $table->integer('view_amount')->unsigned()->default(0)->comment('浏览量');
            $table->integer('like_amount')->unsigned()->default(0)->comment('点赞量');
            $table->integer('collect_amount')->unsigned()->default(0)->comment('收藏量');
            $table->integer('sort')->default(0)->comment('排序');
            $table->boolean('is_show')->default(1)->comment('展示');
            $table->index(['title']);
            $table->timestamps();
        });

        Schema::create('news_likes', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('user_id')->comment('用户id');
            $table->integer('news_id')->comment('消息id');
            $table->timestamps();
        });

        Schema::create('news_collects', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('user_id')->comment('用户id');
            $table->integer('news_id')->comment('消息id');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('news');
        Schema::dropIfExists('news_likes');
        Schema::dropIfExists('news_collects');
    }
}
